<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-col :span="24">
          <el-form-item label="车场名称" prop="chname">
            <el-input v-model="formData.chname" placeholder="请输入车场名称" :disabled='true' clearable
                      :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="节假日名称" prop="holidayName">
            <el-input v-model="formData.holidayName" placeholder="请输入节假日名称" clearable :disabled='disabled'
                      :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开始时间" prop="beginTime">

            <el-date-picker
              v-model="formData.beginTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期时间"
              :disabled='disabled'>
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结束时间" prop="endTime">

            <el-date-picker
              v-model="formData.endTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期时间"
              :disabled='disabled'>
            </el-date-picker>

          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">返回</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import {addHolidays, getHolidays} from "@/api/modules/sys-cars-home/api/holidays";
import path from "path";

export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        chname: undefined,
        chid: undefined,
        holidayName: undefined,
        beginTime: null,
        endTime: null,
      },
      disabled:false,
      rules: {
        chname: [{
          required: true,
          message: '请输入车场名称',
          trigger: 'blur'
        }],
        holidayName: [{
          required: true,
          message: '请输入节假日名称',
          trigger: 'blur'
        }],
        beginTime: [{
          required: true,
          message: '请选择开始时间',
          trigger: 'change'
        }],
        endTime: [{
          required: true,
          message: '请选择结束时间',
          trigger: 'change'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    this.formData.chname = this.$route.query.chname
    listen()
  },
  mounted() {
  },
  methods: {

    listen() {
      if (this.$route.query.message == "新增") {
          this.disabled=false
      } else if (this.$route.query.message == "修改") {
        this.disabled=false
        this.formData.id = this.$route.query.id
        getHolidays(this.formData.id).then(response => {
          this.formData = response.data;
        });
      } else if (this.$route.query.message == "查看") {
        this.disabled=true

      }
    },

    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (valid) {
          if (this.$route.query.message == "新增") {
            this.formData.chid = this.$route.query.chid
            console.log(this.formData)
            addHolidays(this.formData).then(res => {
              if (res.code == 200) {
                this.$modal.msgSuccess("新增成功");
              }
              this.goback()
            })
          } else if (this.$route.query.message == "修改") {


          }

        }

      })
    },
    resetForm() {

      this.$store.dispatch('tagsView/delAllViews',this.$router);
      this.goback()
    },
    goback() {
      this.$router.push({
        path: "carshomerule", query: {
          chid: this.$route.query.chid,
          chname: this.$route.query.chname,
        }
      })
    },
  }
}

</script>
<style>
</style>

